/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2024 All Rights Reserved.
 */
package com.alipay.demo.controller;

import com.alipay.api.response.AlipayMarketingImageListQueryResponse;
import com.alipay.api.response.AlipayMarketingImagedirectoryListQueryResponse;
import com.alipay.demo.service.ImageUploadService;
import com.alipay.demo.vo.ImageDirectoryRequest;
import com.alipay.demo.vo.OpenResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.google.common.collect.Lists;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jishupei.jsp
 * @version : ImageController, v0.1 2024年05月21日 3:29 下午 jishupei.jsp Exp $
 */
@Api(tags = "图片管理模块")
@ApiSupport(order = 5)
@RestController
@RequestMapping(value = "/image")
public class ImageController {

    @Autowired
    private ImageUploadService imageUploadService;

    /**
     * 图片空间目录创建
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "图片空间目录创建")
    @PostMapping(value = "/directory/create")
    public OpenResponse<String> imageDirectoryCreate(@RequestBody ImageDirectoryRequest request) {
        return imageUploadService.createImageDirectory(request);
    }

    /**
     * 图片空间目录修改
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "图片空间目录修改")
    @PostMapping(value = "/directory/update")
    public OpenResponse<Void> imageDirectoryUpdate(@RequestBody ImageDirectoryRequest request) {
        return imageUploadService.updateImageDirectory(request);
    }

    /**
     * 分页查询图片空间目录
     */
    @ApiOperation(value = "分页查询图片空间目录")
    @ApiOperationSupport(order = 3)
    @GetMapping(value = "/directory/list")
    public OpenResponse<AlipayMarketingImagedirectoryListQueryResponse> queryList(@ApiParam(value = "页码，默认1", defaultValue = "1") Long pageNum,
                                                                                  @ApiParam(value = "单页大小，默认10", defaultValue = "10") Long pageSize,
                                                                                  ImageDirectoryRequest request) {
        return imageUploadService.queryImageDirectoryList(pageNum, pageSize, request);
    }

    /**
     * 图片信息修改
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "图片信息修改")
    @GetMapping(value = "/update")
    public OpenResponse<Void> imageUpdate(@ApiParam(value = "图索引id") String imageIndexId,
                                          @ApiParam(value = "修改后新文件名") @RequestParam(required = false) String fileName,
                                          @ApiParam(value = "修改后新目录id") @RequestParam(required = false) String imageDirectoryId) {
        return imageUploadService.updateImage(imageIndexId, fileName, imageDirectoryId);
    }

    /**
     * 图片分页查询
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "图片分页查询")
    @GetMapping(value = "/list")
    public OpenResponse<AlipayMarketingImageListQueryResponse> imageList(@ApiParam(value = "页码，默认1", defaultValue = "1") Long pageNum,
                                                                         @ApiParam(value = "单页大小，默认10", defaultValue = "10") Long pageSize,
                                                                         @ApiParam(value = "图索引id") String imageIndexId,
                                                                         @ApiParam(value = "图文件名") @RequestParam(required = false) String fileName,
                                                                         @ApiParam(value = "图归属目录id") @RequestParam(required = false) String imageDirectoryId) {
        return imageUploadService.queryImageList(pageNum, pageSize, imageIndexId, fileName, imageDirectoryId);
    }

    /**
     * 图片删除
     */
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "图片删除")
    @GetMapping(value = "/delete")
    public OpenResponse<Void> imageDelete(@ApiParam(value = "图索引id列表，逗号隔开") String imageIndexIds) {
        return imageUploadService.deleteImage(Lists.newArrayList(
                StringUtils.split(imageIndexIds,",")));
    }
}
